#include "Stage_1.h"
#include "ThorSceneManager.h"
#include "StormLightning.h"
#include "EffectManager.h"

#include "savage.h"
#include "pig.h"
#include "yumi.h"

int ri = 1;
extern OgreCanvas * gc;
void Stage_1::_createSprites()
{
	Scene::_createSprites();
	_createOneSprite(Ogre::String("yuanshiren01.mesh"), SAVAGE, "savage1");
	Sprite *_spriteTmp = getNPCSprite(Ogre::String("savage1"));
	_spriteTmp->attachSkeletonEquipment(Ogre::String("bangzi01.mesh"),1);
	_spriteTmp->setCenterOffset(Vector3(0.0f,2.4969f/4.f,0.0f));
	_spriteTmp ->setPosition(Vector3(10,0,10));
	_createOneSprite(Ogre::String("yuanshirenB.mesh"), SAVAGE, "savage2");
	_spriteTmp = getNPCSprite(Ogre::String("savage2"));
	_spriteTmp->attachSkeletonEquipment(Ogre::String("yuanshirenB_weapon.mesh"),1);
	_spriteTmp->setCenterOffset(Vector3(0.0f,2.4969f/4.f,0.0f));
	_spriteTmp ->setPosition(Vector3(15,0,15));

	_createOneSprite(Ogre::String("Box02.mesh"), PIG, "pig1");
	_spriteTmp = getNPCSprite(Ogre::String("pig1"));
	_spriteTmp->setCenterOffset(Vector3(0.0f,1.2791f/4.f,0.0f));
	_spriteTmp ->setPosition(Vector3(2.5f,0.0f, 2.5f));
	_spriteTmp->createFX(dynamicsWorld);
	_spriteTmp->setFXDisabled();
	_spriteTmp->setFXVolumn();
	_spriteTmp->setEnableCollision(false);
}

Sprite* Stage_1::_createOneSprite(Ogre::String _meshName, int type, Ogre::String spriteName)
{
	Sprite * _sprite;
	switch(type)
	{
	case SAVAGE:
		_sprite = new Savage(m_pSceneMgr, m_pCamera);
		break;
	case PIG:
		_sprite = new Pig(m_pSceneMgr, m_pCamera);
		break;
	case YUMI:
		_sprite = new Yumi(m_pSceneMgr, m_pCamera);
		break;
	}
	_sprite->init(spriteName);
	_sprite->mType = type;
	_sprite->load(_meshName);
	std::pair<Ogre::String, Sprite *> _pair;
	_pair.first = spriteName;
	_pair.second = _sprite;
	m_vNpc.insert(_pair);
	_sprite->_createShadow(true);
	_sprite->setPosition(Ogre::Vector3(500.0f,0.0f, 300.0f*1.414f));
	_sprite->setOrientation(Ogre::Quaternion::IDENTITY);
	_sprite->setScale(Ogre::Vector3(1.0f,1.0f,1.0f));
	_sprite->mDestination = _sprite->mPosition;
	_sprite->mAngularDestination = Ogre::Vector3(0,0,1);



	return _sprite;


}

void Stage_1::eventClick(int _xx, int _yy)
{
	Scene::eventClick(_xx,_yy);	

	Ogre::Real cloudHeight = 3.0f;


	/*storm lightning event trigger*/
	Ogre::Vector3 p3D =  Sprite::_getInteractPosition3D(m_pCamera,Vector2(_xx,_yy), cloudHeight);
	((StormLightning*)(EffectManager::getInstance()->getEffect("effect1")))
		->setPostionViaCloud(p3D,cloudHeight);
	Vector2 oc =Vector2(_xx, _yy);
	((StormLightning*)(EffectManager::getInstance()->getEffect("effect1")))
		->setOriginalCenter(oc);
	EffectManager::getInstance()->getEffect("effect1")->begin();
	/*******************************/




	
}

void Stage_1::eventMouseMove(int _xx, int _yy, int x_rel, int y_rel, bool isButtonDown)
{
	Scene::eventMouseMove(_xx,_yy,x_rel,y_rel,isButtonDown);

	if(isButtonDown)
	{

	}
}

void Stage_1::eventMouseRelease(int _xx, int _yy)
{
	Scene::eventMouseRelease(_xx, _yy);
}

void Stage_1::load()
{
	Scene::load();

	char _rName[50];
	sprintf(_rName,"yumi%d", ri);
	Sprite * _tmp = _createOneSprite(Ogre::String("yumi.mesh"), YUMI, _rName);
	_tmp->createFX(dynamicsWorld);
	_tmp->setFXDisabled();
	Ogre::Vector3 _p3D = Ogre::Vector3(500.0f,100000, 300.0f*1.414f);
	_tmp->setPosition(_p3D);
	_tmp->setScale(Ogre::Vector3(0.1f,0.1f,0.1f));
	_tmp->setVisable(FALSE);
}

